package com.wangjiyuan.giftshuo.ui.fragment.classify.shop.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.shop.TreeBean;
import com.wangjiyuan.giftshuo.utils.BaseAdapterHelper;

import java.util.List;

import static com.wangjiyuan.giftshuo.R.id.textView_item_shop_tree;

/**
 * 列表的ListView
 * Created by QXL on 2016/11/18.
 */

public class ShopTreeBaseAdapter extends BaseAdapterHelper<TreeBean.DataBean.CategoriesBean> {
    int selectPosition =0;

    public ShopTreeBaseAdapter(Context context, List<TreeBean.DataBean.CategoriesBean> list) {
        super(context, list);
    }

//    获取ListView中item的位置
    public void clearPosition(int position){
        this.selectPosition =position;
    }

    @Override
    public View getItemView(final int position, View convertView, ViewGroup parent) {

        ViewHolderTree viewHolderTree = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_shop_tree, parent, false);
            viewHolderTree = new ViewHolderTree();
            viewHolderTree.textView_item_shop_tree = (TextView) convertView.findViewById(textView_item_shop_tree);
            convertView.setTag(viewHolderTree);
        } else {
            viewHolderTree = (ViewHolderTree) convertView.getTag();
        }
//        关联数据
        TreeBean.DataBean.CategoriesBean bean = mList.get(position);
        viewHolderTree.textView_item_shop_tree.setText(bean.getName());
        viewHolderTree.textView_item_shop_tree.setHeight(80);
        if(selectPosition ==position){
            viewHolderTree.textView_item_shop_tree.setTextColor(mContext.getResources().getColor(R.color.customPink));
            viewHolderTree.textView_item_shop_tree.setBackground(mContext.getResources().getDrawable(R.drawable.tree_bac));
        }
        else {
            viewHolderTree.textView_item_shop_tree.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolderTree.textView_item_shop_tree.setBackgroundColor(mContext.getResources().getColor(R.color.treeBac));
        }

        return convertView;
    }

    class ViewHolderTree {
        TextView textView_item_shop_tree;
    }
}
